﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProjectManager.Properties;
using System.Resources;

namespace ProjectManager.Masters.Library
{
    public partial class TimeDisplay : UserControl
    {
        TimeSpan _value;
        ResourceManager rm = Properties.Resources.ResourceManager;

        public TimeDisplay()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }

        public TimeSpan Value
        {
            get { return _value; }
            set
            {
                _value = value;
                DisplayValue();
            }
                  
        }

        private void DisplayValue()
        {
            int Hd = (_value.Days * 24 + _value.Hours) / 10;
            int Hu = (_value.Days * 24 + _value.Hours) % 10;
            int Md = _value.Minutes / 10;
            int Mu = _value.Minutes % 10;
            int Sd = _value.Seconds / 10;
            int Su = _value.Seconds % 10;

            AssignImage(pcbHd, Hd);
            AssignImage(pcbHu, Hu);
            AssignImage(pcbMd, Md);
            AssignImage(pcbMu, Mu);
            AssignImage(pcbSd, Sd);
            AssignImage(pcbSu, Su);
        }

        private void AssignImage(PictureBox pcb, int value)
        {
            string image = string.Concat("B_", value.ToString("0"));
            Image myImage = rm.GetObject(image) as Image;
            if (myImage != pcb.Image)
                pcb.Image = myImage;
        }
    }
}
